<%@ page language="java" pageEncoding="UTF-8" import="com.chinapost.util.AuthUtil"%>
<%@ taglib prefix="my" uri="/WEB-INF/tlds/permission.tld" %>
<%
	AuthUtil authUtil = new AuthUtil(session);
%>
<script type="text/javascript">
	var wdry_datagrid;
	$(function() {
		wdry_datagrid = $('#wdry_manager_datagrid').datagrid({
			url : '${pageContext.request.contextPath}/wdryAction!datagrid.action',
			pagination : true,
			pageSize : 20,
			pageList : [  10, 20, 30, 40, 50 ],
			border : false,
			fit : true,
			fitColumns : true,
			idField : 'cbh',
			sortName : 'cmodifydate',
			sortOrder : 'desc',
			checkOnSelect : false,
			selectOnCheck : true,
			columns : [ [ {
				checkbox : true
			}, {
				title : '所属机构',
				field : 'deptName',
				align : "center",
				width : 140
			}, {
				title : '网点名称',
				field : 'wdName',
				align : "center",
				width : 140
			}, {
				title : '姓名',
				field : 'cname',
				align : "center",
				width : 80
			},{
				title : '人员编号',
				field : 'cbh',
				align : "center",
				width : 80
			}, 
			{
				title : '性别',
				field : 'csex',
				align : "center",
				width : 60,
			}, {
				title : '用工类别',
				field : 'cyglb',
				align : "center",
				width : 80
			}, {
				field : 'action',
				title : '操作',
				width : 100,
				align : 'center',
				formatter : function(value, row, index) {
					var str='';
                	<%if (authUtil.isAuth("/wdryAction!wdryEdit.action")){%>
                	str += sy.fs('<img onclick="wdryEdit(\'{0}\');" src="{1}" style="cursor: pointer;" title="修改"/>&nbsp;',row.cbh,'${pageContext.request.contextPath}/css/themes/icons/pencil.png');
                	<%}%>
                	<%if (authUtil.isAuth("/wdryAction!delete.action")){%>
                	str += sy.fs('<img onclick="wdryDelete(\'{0}\');" src="{1}" style="cursor: pointer;" title="删除"/>&nbsp;',row.cbh,'${pageContext.request.contextPath}/css/themes/icons/no.png');
                	<%}%>
                	return str;
				}
			} ] ],
			toolbar : '#wdry_toolbar'
		});
		$('#wdry_manager_dept').combotree({
			lines:true,
			url:'deptAction!do_combotree.action',
			panelHeight:280,
			required:true,
			editable:false,
			idField:'id',
			textField:'text',
			parentField:'pid',
			onSelect:function(node){
				//$('#wdry_manager_wd').combobox('reload','wdxxAction!do_combobox.action?deptId='+node.id);
				wdry_showWdSelect(node.id);
			}
		});
		$('#wdry_manager_dept').combotree('setValue','${sessionInfo.deptid}');
		wdry_showWdSelect('${sessionInfo.deptid}');
	});
	
	function wdry_showWdSelect(deptid){
		$.ajax({
			url : '${pageContext.request.contextPath}/wdxxAction!do_combobox.action',
			data : {
				deptId : deptid
			},
			dataType : 'json',
			success : function(d) {
				if (d.length >0){
					$('#wdry_manager_wd_span').show();
					$('#wdry_manager_wd').combobox({
						data:d,
						valueField:'cid',    
					    textField:'cname'   
					});
				}else{
					$('#wdry_manager_wd_span').hide();
					$('#wdry_manager_wd').combobox({
						data:null,
						valueField:'cid',    
					    textField:'cname'   
					});
					$('#wdry_manager_wd').combobox('setValue','');
				}
			}
		});
	}
	
	function wdryEdit(cid) {
		if (cid != undefined) {
			$('#wdry_manager_datagrid').datagrid('unselectAll');
			$('#wdry_manager_datagrid').datagrid('selectRecord', cid);
		}
		var rows = $('#wdry_manager_datagrid').datagrid('getSelected');
		var p = parent.sy.dialog({
			title : '网点人员编辑',
			iconCls : 'icon-edit',
			href : '${pageContext.request.contextPath}/wdryAction!wdryEdit.action',
			width : 530,
			height : 260,
			buttons : [ {
				text : '保存',
				iconCls : 'icon-save',
				handler : function() {
					var f = p.find('form');
					f.form('submit', {
						url : '${pageContext.request.contextPath}/wdryAction!edit.action',
						success : function(d) {
							var json = $.parseJSON(d);
							if (json.success) {
								wdry_datagrid.datagrid('reload');
								p.dialog('close');
							}
							parent.sy.messagerShow({
								msg : json.msg,
								title : '提示'
							});
						}
					});
				}
			} ],
			onLoad : function() {
				var f = p.find('form');
				 $('#wdry_edit_dept').combotree({
						lines:true,
						url:'deptAction!do_combotree.action',
						panelHeight:260,
						required:true,
						editable:false,
						idField:'id',
						textField:'text',
						parentField:'pid',
						 onBeforeSelect: function(node) {
					            if (!$(this).tree('isLeaf', node.target)) {
					                return false;
					            }
					        },
					        onClick: function(node) {
					            if (!$(this).tree('isLeaf', node.target)) {
					                $('#wdry_edit_dept').combo('showPanel');
					            }
					        },
						onSelect:function(node){
							$('#wdry_edit_wd').combobox('setValue','');
							$('#wdry_edit_wd').combobox('reload','wdxxAction!do_combobox.action?deptId='+node.id);
						}
					}); 
				 $('#wdry_edit_wd').combobox({
					 url:'wdxxAction!do_combobox.action?deptId='+rows.deptId,
					 required:true,
					 valueField:'cid',
					 textField:'cname'
				 });
				f.form('load', rows);
				
			}
		});
	};
	function wdryAppend() {
		var p = parent.sy.dialog({
			title : '添加网点人员',
			iconCls : 'icon-append',
			href : '${pageContext.request.contextPath}/wdryAction!wdryAdd.action',
			width : 530,
			height : 260,
			buttons : [ {
				text : '保存',
				iconCls : 'icon-save',
				handler : function() {
					var f = p.find('form');
					f.form('submit', {
						url : '${pageContext.request.contextPath}/wdryAction!add.action',
						success : function(d) {
							var json = $.parseJSON(d);
							if (json.success) {
								wdry_datagrid.datagrid('reload');
								p.dialog('close');
							}
							parent.sy.messagerShow({
								msg : json.msg,
								title : '提示'
							});
						}
					});
				}
			} ]
		});
	}
	function wdryRemove() {
		var rows = wdry_datagrid.datagrid('getChecked');
		var ids = [];
		if (rows.length > 0) {
			parent.sy.messagerConfirm('请确认', '是否删除当前所选记录？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].cbh);
					}
					$.ajax({
						url : '${pageContext.request.contextPath}/wdryAction!delete.action',
						data : {
							ids : ids.join(',')
						},
						dataType : 'json',
						success : function(d) {
							wdry_datagrid.datagrid('load');
							$('#wdry_manager_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
							parent.sy.messagerShow({
								title : '提示',
								msg : d.msg
							});
						}
					});
				}
			});
		} else {
			parent.sy.messagerAlert('提示', '请选择要删除的记录！', 'error');
		}
	};

	function wdryDelete(cbh) {
		$('#wdry_manager_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
		$('#wdry_manager_datagrid').datagrid('checkRow', $('#wdry_manager_datagrid').datagrid('getRowIndex', cbh));
		wdryRemove();
	}


	function wdryImport() {
		var p = parent.sy.dialog({
			title : '导入网点人员数据',
			iconCls : 'icon-import',
			href : '${pageContext.request.contextPath}/wdryAction!wdryImport.action',
			width : 510,
			height : 300,
			buttons : [ {
				text : '导入',
				iconCls : 'icon-accept',
				handler : function() {
					$.ajaxFileUpload({
						url : 'uploadFileAction!upload.action',//用于文件上传的服务器端请求地址  
						secureuri : false,//一般设置为false  
						fileElementId : 'wdry_import_file',//文件上传空间的id属性  <input type="file" id="file" name="file" />  
						dataType : 'text',//返回值类型 json，text  
						success : function(d, status) //服务器成功响应处理函数  
						{
							var json = $.parseJSON(d);
							if (json.state) {
								$.messager.progress({
									text : '正在处理，请稍候...',
									interval : 100
								});
								$.post("wdryAction!addWdrys.action", {
									filename : json.filename,
									deptId : $('#wdry_import_dept').combotree('getValue')
								}, function(rsp) {
									if (rsp.success) {
										wdry_datagrid.datagrid('reload');
										p.dialog('close');
									}
									$.messager.progress('close');
									parent.sy.messagerAlert('提示', rsp.msg, 'info');
								}, "JSON");
							} else {
								$.messager.progress('close');
								parent.sy.messagerShow({
									msg : json.msg,
									title : '提示'
								});
							}
						},
						error : function(data, status, e)//服务器响应失败处理函数  
						{
							parent.sy.messagerAlert('错误', e, 'error');
						}
					});
				}
			} ]
		});
	};


	function _searchWdry() {
		wdry_datagrid.datagrid('load', sy.serializeObject($('#wdry_search_form')));
		wdry_datagrid.datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
	};
	function _cleanSearchWdry() {
		$('#wdry_search_form  input[name="cname"]').val('');
		$('#wdry_manager_wd').combobox('setValue','');
		$('#wdry_manager_dept').combotree('setValue','${sessionInfo.deptid}');
		wdry_datagrid.datagrid('load', sy.serializeObject($('#wdry_search_form')));
		wdry_datagrid.datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
	};
</script>




<div class="easyui-layout" data-options="fit:true" style="overflow: hidden;">
	<div data-options="region:'north',title:'查询网点',iconCls:'icon-search'" style="height: 80px;padding:5px;overflow: hidden;">
		<div style="padding:5px">
			<form method="post" id="wdry_search_form" style="display:inline">
			<span>所属机构：</span>
			<input type="text" id="wdry_manager_dept"  name="deptId" style="width:200px"/>&nbsp;&nbsp;
			<span id="wdry_manager_wd_span">所属网点：
				<input type="text" id="wdry_manager_wd"  name="wdid"  style="width:180px"/>&nbsp;&nbsp;	
			</span>
			<span> 姓名：</span> <input type='text' name='cname' style="width:100px"/>
			</form>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="_searchWdry();">查询</a>&nbsp; <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onClick="_cleanSearchWdry();">清空</a>
		</div>
	</div>
	<div data-options="region:'center',title:'人员列表',border:true,iconCls:'icon-application'" style="overflow: hidden;">
		<table id="wdry_manager_datagrid"></table>
	</div>
</div>
<div id="wdry_toolbar" style="display: none;" >
<table  class="toolbar" >
	<tr>
		<my:per url="/wdryAction!wdryAdd.action">
		<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-append',plain:true" onclick="wdryAppend();">新增</a></td>
		<td><div class="datagrid-btn-separator"></div></td>
		</my:per>
		<my:per url="/wdryAction!delete.action">
		<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-delete',plain:true" onclick="wdryRemove()">批量删除</a></td>
		<td><div class="datagrid-btn-separator"></div></td>
		</my:per>
		<my:per url="/wdryAction!wdryImport.action">
		<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-import',plain:true" onclick="wdryImport()">批量导入</a></td>
		<td><div class="datagrid-btn-separator"></div></td>
		</my:per>
	</tr>
</table>
</div>
